import abc #利用abc模块实现抽象类

class Component(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def init(self):
        pass
    @abc.abstractmethod
    def doSelfTest(self):
        pass
class Keyboard(Component):
    def init(self):
        print("系统初始化")
    def doSelfTest(self):
        print("进行自检")
    @abc.abstractmethod
    def getSelectedKey(self):
        pass
class ActionKeyboard(Keyboard):
    def getSelectedKey(self):
        print("获取用户输入按键值")
    def getAction(self):
        print("继续或取消操作")
class TicketKindKeyboard(Keyboard):
    def getSelectedKey(self):
        Ticketkind = input("选择车票种类（飞机票、高铁、火车）：")
        TicketSelect = input("选择车票类型(单程票、往返票)：")
        print("获取车票种类为:"+str(Ticketkind+TicketSelect))
    def getTicketKind(self):
        print("正在购买该车票中")
class DestinationKeyboard(Keyboard):
    def getSelectedKey(self):
        destination = input("请输入目的地代码:")
        print("目的地代码为："+destination)
    def getDestinationCode(self):
        print("代码显示目的地为成都双流机场")

class Screen(Component):
    def init(self):
        print("系统初始化")
    def doSelfTest(self):
        print("进行自检")
    def showText(self):
        print("正在显示乘客车票信息")
class CarDriver(Component):
    def init(self):
        print("初始化")
    def doSelfTest(self):
        print("自检")
    def getCredit(self):
        print("读取现金卡金额")
    def debitFare(self):
        print("刷新现金卡余额")
    def ejectMCard(self):
        print("退卡")
class CashSlot(Component):
    def init(self):
        print("系统初始化")
    def doSelfTest(self):
        print("进行自检")
    def getCredit(self):
        print("读取现金金额")
class Printer(Component):
    def init(self):
        print("系统初始化")
    def doSelfTest(self):
        print("进行自检")
    def printTicket(self):
        print("打印车票中")
    def ejectTicket(self):
        print("正在出票中")
class TicketSoldSystem():
    def __init__(self):
        self.screen = Screen()
        self.carDriver = CarDriver()
        self.cashSlot = CashSlot()
        self.actionKeyboard = ActionKeyboard()
        self.ticketKindKeyboard = TicketKindKeyboard()
        self.destinationKeyboard = DestinationKeyboard()
        self.printer = Printer()
    def verifyCredit(self):
        print("扣款金额验证中")
    def calculateFare(self):
        self.destinationKeyboard.getSelectedKey()
        self.destinationKeyboard.getDestinationCode()
        pay_way = input("请选择支付方式：1(现金卡)、2（硬币或纸币）")
        if int(pay_way) == 1:
            self.carDriver.getCredit()
            self.ticketKindKeyboard.getSelectedKey()
            print("车票费用为2.5")
            self.verifyCredit()
            self.carDriver.ejectMCard()
        else:
            self.cashSlot.getCredit()
            self.ticketKindKeyboard.getSelectedKey()
            print("车票费用为2.5")
            self.verifyCredit()
        self.screen.showText()
        self.printer.printTicket()
        self.printer.ejectTicket()

Ticket = TicketSoldSystem()
Ticket.calculateFare()